package com.cnr.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;

import com.sun.mail.util.BASE64DecoderStream;

public class PasswordUtil {

	private static final Logger logger = Logger.getLogger(PasswordUtil.class);
	
	public static char[] encrypt(char[] password){
		char[] result = null;
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-256");
			md.update(password.toString().getBytes());
			byte[] dp = md.digest();
			result = BASE64DecoderStream.decode(dp).toString().toCharArray();
		} catch (NoSuchAlgorithmException e) {
			logger.error("Password encrypting algorithm not found. Password digestion failed.");
		}
		return result;
	}
	
}
